import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
		navIndex:0,
		songItem:null,
		nowList:[],
		historyList:[]
	},
    mutations: {
		clickNav(state,payload){
			state.navIndex = payload
		},
		//播放歌曲
		xplaysong(state,payload){
			state.songItem = payload
			this.commit("xsavehistoryList",payload)
		},
		//储存当前歌单
		xsavenowList(state,payload){
				state.nowList=payload
				localStorage.setItem("nowList",JSON.stringify(state.nowList))			
		},
		//储存历史播放
		xsavehistoryList(state,payload){
			// console.log(state.newList);
			if (
				 //找不到对象推入
				 JSON.stringify(state.historyList).indexOf(
				JSON.stringify(payload)
				) == -1
				) {
					state.historyList.push(payload)
					localStorage.setItem("historyList",JSON.stringify(state.historyList))
				 //找到对象筛选删除
				 }
			
			
		}
	},
    actions: {}
})
